package csel.controller.decoders;

import csel.controller.bindings.ActionCommandBindings;
import csel.controller.commandutil.CommandPool;
import csel.controller.dispatchers.Dispatcher;
import csel.controller.enums.ActionEnum;
import csel.controller.enums.CommandEnum;
import csel.controller.events.Action;
import csel.controller.events.Event;
import csel.model.GameCommand;

/**
 * Purpose: implements the functionality of an EventDecoder for
 * the Splash View, Status View, and Area View
 * 
 * @author Nikolas Wolfe
 */

public class ActionEventDecoder extends EventDecoder<Action>
{
	private final CommandPool pool;
	private final ActionCommandBindings actionCommandBindings;

	public ActionEventDecoder(CommandPool pool, 
			Dispatcher disp)
	{
		super( disp );
		this.pool = pool;
		actionCommandBindings = ActionCommandBindings.getInstance();
	}

	protected GameCommand parseEvent(Event event)
	{
		ActionEnum actionEnum = event.getActionEnum();
		CommandEnum commandEnum = actionCommandBindings.getEnum(actionEnum);
		if( commandEnum == null)
		{
			throw new IllegalStateException(
					"The program attempted to use an invalid key command");
		}
		return pool.getCommand(commandEnum, event);
	}
}
